package com.yt.db.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

@Configuration()
public class DataSourceConfiguration {

    @Bean("dataSourceWirte")
    @ConfigurationProperties(prefix = "spring.datasource-write")
    public DataSource dataSourceWirte() {
        return DataSourceBuilder.create().build();
    }

    @Bean("dataSourceRead")
    @ConfigurationProperties(prefix = "spring.datasource-read")
    public DataSource dataSourceRead() {
        return DataSourceBuilder.create().build();
    }

    @Primary
    @Bean("dataSource")
    public DataSource dataSource() {
        return new DynamicDataSource();
    }

}
